package com.eqdd.yiqidian.kotlin

import android.app.Activity
import android.content.Context
import android.support.design.widget.BottomSheetDialog
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import com.eqdd.yiqidian.base.BaseActivity
import com.eqdd.yiqidian.kotlin.utils.AreaUtil
import com.eqdd.yiqidian.kotlin.utils.DialogUtil
import com.eqdd.yiqidian.kotlin.utils.PopWindowUtil
import com.eqdd.yiqidian.kotlin.utils.TimePickerUtil
import com.eqdd.yiqidian.utils.ImageShowUtil
import com.eqdd.yiqidian.widget.ChooseAlertView
import com.luck.picture.lib.entity.LocalMedia
import com.xujiaji.happybubble.BubbleDialog
import java.util.*

/**
 * Created by jhj on 18-6-23.
 */

val Activity.inflater: LayoutInflater
    get() = LayoutInflater.from(this)


val Context.inflater: LayoutInflater
    get() = LayoutInflater.from(this)

fun <T> List<T>.toArrayList(): ArrayList<T> {
    return ArrayList(this)
}

// ========= 图片列表中展示 =========
fun Activity.listImagePreview(imgPath: String, imageView: ImageView) {
    ImageShowUtil.setListImgPreview(this, imgPath, imageView)
}

fun Activity.listImagePreview(imgList: List<String>, recyclerView: RecyclerView, showNum: Int = 3) {
    ImageShowUtil.setListImgPreview(this, imgList, recyclerView, showNum)
}


// ========= 图片点击预览 =========
fun Activity.localMediaImgPreview(localMedia: LocalMedia) {
    localMediaImgPreview(listOf(localMedia), 0)
}

fun Activity.localMediaImgPreview(imgList: List<LocalMedia>, position: Int) {
    ImageShowUtil.localMediaImgPreview(this, position, imgList)
}

fun Activity.imgPathPreview(imgPath: String) {
    imgPathPreview(listOf(imgPath), 0)
}

fun Activity.imgPathPreview(imgList: List<String>, position: Int) {
    ImageShowUtil.imgPathPreview(this, position, imgList)
}


//========= 删除 =========

fun BaseActivity.deleteDialog(url: String, msg: String, vararg params: Pair<String, Any?>, isFinish: Boolean = true, body: () -> Unit = {}) {
    DialogUtil.delete(this, url, msg, isFinish, *params) {
        body()
    }
}


/**
 * 导航栏
 */
fun Activity.popMenu(list: List<String>, view: View, body: (bubbleDialog: BubbleDialog, position: Int) -> Unit) {
    PopWindowUtil.popMenu(this, list, view, body)
}

fun Activity.bottomDialog(list: List<String>, title: String? = null, body: (pos: Int) -> Unit) {
    ChooseAlertView.getBottomChoose(this, title, list) { o, pos ->
        body(pos)
    }.show()
}


fun Activity.bottomCustomDialog(layoutRes: Int, body: (v: View, dialog: BottomSheetDialog) -> Unit) {
    DialogUtil.bottomCustom(this, layoutRes, body)
}


fun Activity.timePicker(startDate: Date?, endDate: Date?, type: BooleanArray = TimePickerUtil.type1, isUpper: Boolean = false,
                        body: (date: Date) -> Unit, calculate: (millis: Long) -> Unit = {}) {
    TimePickerUtil.timePicker(this, startDate, endDate, isUpper, type, body, calculate)
}


fun BaseActivity.areaSelect(body: (province: String,city: String,district: String) -> Unit) {
    AreaUtil.initAreaDialog(this, body)
}





